package com.drinks.yiniang.adapter.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.drinks.yiniang.R;
import com.drinks.yiniang.entity.user.wine.WineListJson;
import com.hansen.library.Constants;
import com.hansen.library.ui.widget.image.RatioRoundImageView;
import com.hansen.library.utils.CommonUtils;
import com.hansen.library.utils.StringUtils;

import java.util.List;

/**
 * 酒类分析 adapter
 *
 * Created by han on 2019/6/27 0027.
 */

public class WineListAdapter extends BaseAdapter {
    private Context mContext;

    private List<WineListJson.WineList> mList;

    private LayoutInflater inflater;

    public WineListAdapter(Context mContext, List<WineListJson.WineList> mList) {
        this.mContext = mContext;
        this.mList = mList;

        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return CommonUtils.getListSize(mList);
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder mHolder = null;

        if (convertView == null) {
            mHolder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_dialog_wine_list, null);

            mHolder.iv_wine_list_cover = convertView.findViewById(R.id.iv_wine_list_cover);
            mHolder.tv_wine_list_name = convertView.findViewById(R.id.tv_wine_list_name);

            convertView.setTag(mHolder);
        } else {
            mHolder = (ViewHolder) convertView.getTag();
        }

        WineListJson.WineList data = mList.get(position);

        mHolder.tv_wine_list_name.setText(Constants.STATUS_GLOBAL_YES.equals(data.getIs_default()) ? StringUtils.getNullEmptyConvert__(data.getTitle()) + "(默认)" : StringUtils.getNullEmptyConvert__(data.getTitle()));

        return convertView;
    }

    class ViewHolder {
        //封面
        RatioRoundImageView iv_wine_list_cover;
        //酒单名称
        TextView tv_wine_list_name;
    }
}
